package ar.com.angrymachine.hunter.activities;

import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;

import ar.com.angrymachine.hunter.Game;
import ar.com.angrymachine.hunter.GameSettings;
import ar.com.angrymachine.hunter.GraphicStyles;
import ar.com.angrymachine.hunter.Locale;
import ar.com.angrymachine.hunter.HunterResourceManager;
import ar.com.angrymachine.hunter.gameplay.Quest;

public class QuestActivity extends IncrementalActivity
{
	private Quest quest;
	
	public QuestActivity(Quest quest)
	{
		this.quest = quest;
	}
	
	protected int getCompletionTime()
	{
		return GameSettings.DEFAULT_QUEST_TIME;
	}

	protected boolean onCompletion()
	{
		return true;
	}

	public String getDescription()
	{
		return Locale.getQuestBrief(quest);
	}

	public String getActionText()
	{
        if(isCompleted())
        {
            return Locale.ACCEPTED;
        }
        else
        {
        	if(isRunning())
        	{
        		return Locale.NEGOTIATING;
        	}
        	else
        	{
        		return Locale.NEGOTIATE;
        	}
        }
	}

	public void paint(Graphics g, Rectangle activityArea)
	{
        GraphicStyles.paintDefaultActivity(g, this, activityArea, HunterResourceManager.getImage("quest.png"));
        if(!isCompleted())
        {
        	Rectangle bar = GraphicStyles.getBarArea(activityArea);
            g.setColor(Color.YELLOW);
            GraphicStyles.paintLabeledBar(g, Locale.SIGNING, bar, currentTime, getCompletionTime());
        }
	}
	
	public void onFinished()
	{
		Game.current.goToLocation(quest.generateZone());
	}

	public void update(int delta, boolean action, boolean timeIsRunning)
	{
		super.update(delta, action, timeIsRunning);
		if(timeIsRunning && !action)
		{
			reset();
		}
	}
}
